
const { dbMgr } = require('../config')
const pick = require('lodash/pick')
const { obd_collection } = require('../config')
// console.log(dbMgr)
exports.main = async (event, context) => {
  const { data } = event;

  const condi = pick(data, ['assign', 'isNewAdd', 'region', 'grid', 'staffName'])
  const assign = condi.assign
  const isNewAdd = condi.isNewAdd

  if (assign) {
    condi.staff = assign === '1' ? { $ne: '' } : { $eq: '' }
  }


  if (isNewAdd) {
    if (condition.isNewAdd == "是") {
      condi.isNewAdd = condition.isNewAdd;
    } else {
      condi.isNewAdd = { $or: [{ $ne: '是' }, { $exist: false }] };
    }
  }

  console.log(condi)
  let result = await dbMgr.database.export(
    obd_collection,
    {
      ObjectKey: 'OBD数据' + (new Date().getTime()) + '.csv'
    },
    {
      FileType: 'csv',
      Query: JSON.stringify(condi),
      Fields: '_id,ID,fgqmc,grid,olt,oltpon,region,remark,sqid,sqmc,ssdx,ssdxlx,staff,staffName,portOccupy,isNewAdd',
    }
  )
  // const { JobId } = result
  return result
}
